<?php
@ini_set('display_errors',1);
error_reporting(E_ALL);
require 'kernel/common.php';

if(!$Session->check_admin()) 
    redirect('index.php');

if(isset($_POST['send_setting']))
{
	unset($_POST['send_setting']);
    
	//$_POST['contenue_accueil'] = base64_encode($_POST['contenue_accueil']);
	//$_POST['footer_text'] = base64_encode($_POST['footer_text']);
	//$_POST['google_analytics']	= base64_encode($_POST['google_analytics']);
    //$_POST['url_site']  =  addslashes($_POST['url_site']);
	//$SettingUpdate = serialize($_POST);	
	
    //$GLOBALS['db']->sql_query("UPDATE immo_config SET setting = '". $SettingUpdate ."' WHERE module = 'generale'");
    
    foreach($_POST as $key => $value)
    {
        $GLOBALS['db']->exec("UPDATE immo_config SET setting = '" . $value . "' WHERE module = '". $key ."'");
    }

    
    $GLOBALS['smarty']->assign('error_msg', true);
    $GLOBALS['smarty']->assign('error_class', 'error_ok');
    $GLOBALS['smarty']->assign('error_image', 'comment_ok');
    $GLOBALS['smarty']->assign('error_message',$lang['Configuration_sauvegardee']);
    $GLOBALS['smarty']->assign('url_site',$config['url']);
    
    $GLOBALS['cache']->remove('setting_immophp');
}

$setting_adm = array();
$Sql = $GLOBALS['db']->sql_query("SELECT setting FROM immo_config WHERE module = 'generale'");
$SqlSetting = $db->sql_fetcharray($Sql);
$setting_adm = unserialize($SqlSetting['setting']);

# determination accueil
$page_accueil = '<select name="page_accueil">';
if($setting_adm['page_accueil'] == '')
    $page_accueil .= '<option value="" selected="selected">Default</option>';
else
    $page_accueil .= '<option value="">Default</option>';

$db->sql_query("SELECT * FROM immo_plugins WHERE fichier = 'Page' AND actif = '1' AND install = '1'");
if($db->nb_resultat == 1)
{
    # Listing des page dispo
    $Sql = $db->sql_query("SELECT * FROM immo_page ORDER BY name");
    while($Page = $db->sql_fetchobject($Sql))
    {
        if($setting_adm['page_accueil'] == 'page.php?page='. $Page->id)
            $page_accueil .= '<option value="page.php?page='. $Page->id .'" selected="selected">Page -> '. $Page->name .'</option>';
        else
            $page_accueil .= '<option value="page.php?page='. $Page->id .'">Page -> '. $Page->name .'</option>';
    }
}
$page_accueil .= '</select>';

$setting_adm['google_analytics'] = stripslashes(base64_decode($setting_adm['google_analytics']));

$GLOBALS['smarty']->assign('footer_text', get_ckeditor('footer_text',base64_decode($setting_adm['footer_text']), 'simple') );
$GLOBALS['smarty']->assign('accueil_text', get_ckeditor('contenue_accueil', base64_decode($setting_adm['contenue_accueil'])) );
$GLOBALS['smarty']->assign('page_accueil', $page_accueil);
$GLOBALS['smarty']->assign('theme', liste_theme_select() );
$GLOBALS['smarty']->assign('setting', $setting_adm);

$GLOBALS['smarty']->assign('lang', $lang);

$GLOBALS['smarty']->display('setting.tpl');

/*
$template->set_filenames(array('setting' => 'template/setting.tpl'));
$template->assign_vars(array(
'V_TITRE_SITE'	=>	$setting['titre_site'],
'V_MOT_CLE'	=>	$setting['keywords'],
'V_DESCRIPTION_SITE'	=>	$setting['description_site'],
'V_ANNONCE_PAR_PAGE'	=>	$setting['annonce_par_page'],
'V_CONTENUE_ACCUEIL'	=>	get_ckeditor('contenue_accueil', base64_decode($setting_adm['contenue_accueil'])),
'V_GOOGLE_IDENTIFIANT_SITE'	=>	$setting['google_identifiant_site'],
'V_GOOGLEMAP_KEY'	=>	$setting['googlemap_key'],
'V_CODE_GOOGLE_ANALYTICS'	=>	stripslashes(base64_decode($setting_adm['google_analytics'])),
'V_EMAIL_CONTACT'	=>	$setting['email_contact'],
'V_FOOTER_TEXT'	=>	get_ckeditor('footer_text',base64_decode($setting_adm['footer_text']), 'simple'),
'V_AFFICHE_SECTEUR_ANNONCE'	=>	$setting['affiche_secteur_annonce'],
'V_AFFICHE_VILLE_ANNONCE'   =>  $setting['affiche_ville_annonce'],
'V_AFFICHE_FLUX_ANNONCE'    =>  $setting['affiche_flux_annonce'],
'V_LOG_IDENTIFICATION'  =>  $setting['log_identification'],
'V_IMAGE_CAPTCHA_IDENTIFICATION'    =>  $setting['image_captcha_identification'],
'V_THEME'	=>	liste_theme_select(),
'V_MAP_ACCUEIL'	=>	$setting['map_accueil'],
'V_DVLP_MOD'	=>	$setting['dvlp_mod'],
'V_URL_REWRITE'	=>	$setting['url_rewrite'],
'V_PAGE_ACCUEIL'    =>  $page_accueil,
'V_CONFIG_URL'  =>  $config['url'],
'L_AFFICHE_MAP_ACCUEIL'	=>	$lang['Affiche_carte_accueil'],
'L_DVLP_M0D'	=>	$lang['Dvlp_mod'],
'L_REECRITURE_URL'	=>	$lang['Reecriture_url'],
'L_ENREGISTRER'	=>	$lang['Enregistrer'],
'L_RETOUR'	=>	$lang['Retour'],
'L_TITRE_SITE'	=>	$lang['Titre_site'],
'L_MOT_CLE'	=>	$lang['Mot_cle'],
'L_SEPARER_PAR_VIRGULE'	=>	$lang['Separer_par_virgule'],
'L_CONFIGURATION'	=>	$lang['Configuration'],
'L_EMAIL_CONTACT'	=>	$lang['Email_contact'],
'L_DESCRIPTION_SITE'	=>	$lang['Description_site'],
'L_ANNONCE_PAR_PAGE'	=>	$lang['Annonce_par_page'],
'L_AFFICHE_SECTEUR_ANNONCE'	=>	$lang['Affiche_secteur_annonce'],
'L_NON'	=>	$lang['Non'],
'L_OUI'	=>	$lang['Oui'],
'L_CONTENUE_ACCUEIL'	=>	$lang['Contenu_accueil'],
'L_MESSAGE_BAS_PAGE'	=>	$lang['Message_bas_page'],
'L_GOOGLE_IDENTIFIANT_SITE'	=>	$lang['Google_identifiant_site'],
'L_GOOGLEMAP_CLE_API'	=>	$lang['Google_map_cle_api'],
'L_CODE_GOOGLE_ANALYTICS'	=>	$lang['Google_analytics_code'],
'L_THEME'	=>	$lang['Theme'],
'L_AFFICHE_VILLE_ANNONCE'   =>  $lang['Affiche_ville_annonce'],
'L_ACTIVEE' =>  $lang['Activee'],
'L_DESACTIVEE'   =>  $lang['Desactivee'],
'L_LOG_IDENTIFICATION'  =>  $lang['Log_identification'],
'L_IMAGE_CAPTCHA_IDENTIFICATION'    =>  $lang['Image_captcha_indentification'],
'L_ACCUEIL' =>  $lang['Accueil'],
'L_GENERALE'    =>  $lang['Generale'],
'L_ANNONCE' =>  $lang['Annonce'],
'L_AFFICHE_FLUX_ANNONCE'    =>  $lang['Affiche_flux_annonce'],
'L_SECURISATION_ADMINISTRATION' =>  $lang['Securisation_administration'],
'L_AUTRE'   =>  $lang['Autre'],
'L_OUTILS_GOOGLE'   =>  $lang['Outils_google'],
));

$template->display('setting');*/
require 'footer.php';
?>